#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MEM(a,b) memset(a,(b),sizeof(a)) #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MP make_pair #define pb push_back typedef long long LL; typedef pair pi; #define maxn 60000 #define maxq 250000 #define maxv 100000000 pi pts[2*maxn+1]; LL area(pi A,pi B,pi C) { LL ret = A.first*(B.second-C.second) + B.first*(C.second-A.second)+ C.first*(A.second-B.second); if(ret<0) ret=-ret; return ret; } // 2 binary searches int solve(int a,int b,int c,LL s) { int lo=a+1,hi=c,ret=0,x=-1; while(lo<=hi) { int mid=(lo+hi)/2; LL ar= area(pts[a],pts[b],pts[mid]); if(ar>=2*s) hi=mid-1; else x=mid,lo=mid+1; } if(x!=-1) ret+= (x-a); lo=c+1,hi=b-1,x=-1; while(lo<=hi) { int mid=(lo+hi)/2; LL ar= area(pts[a],pts[b],pts[mid]); if(ar>=2*s) lo=mid+1; else x=mid,hi=mid-1; } if(x!=-1) ret+= (b-x); return ret; } // finds the point with the maximum area triangle when two vertices are point // a and b ( by ternary search) int getPeak(int a,int b) { int lo=a+1,hi=b-1,x=-1; LL best=-1; while(hi-lo>1) { int l1 = (2*lo+hi)/3; int l2 = (lo+2*hi)/3; LL c1 = area(pts[a],pts[b],pts[l1]); LL c2 = area(pts[a],pts[b],pts[l2]); if(c1>c2) hi=l2-1; else lo=l1+1; if(c1>best) best=c1,x=l1; if(c2>best) best=c2,x=l2; } if(lo>a && lobest) best=area(pts[a],pts[b],pts[lo]),x=lo; if(hi>a && hibest) best=area(pts[a],pts[b],pts[hi]),x=hi; return x; } int main() { int i,j,k,T,m,n,q; scanf("%d%d",&n,&q); assert(n>=3 && n<=maxn && q>=1 && q<=maxq); for(i=0;i=0 && a=0 && b=1 && S<=maxs); if(a>b) swap(a,b); int ans=0; int x=getPeak(a,b); int p1,p2; if(x!=-1) ans+=(p1=solve(a,b,x,S)); int y=getPeak(b,a+n); if(y!=-1) ans+=(p2=solve(b,a+n,y,S)); ans = n-2-ans; printf("%d\n",ans); } return 0; }